//
//  YPhoto.m
//  TestZoomPhoto
//
//  Created by yull on 14/12/6.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "YPhoto.h"
#import "SDWebImageManager.h"

@implementation YPhoto

- (instancetype)init
{
    if (self = [super init]) {
        
    }
    return self;
}

- (BOOL)hasBig
{
    return [[SDWebImageManager sharedManager] cachedImageExistsForURL:[NSURL URLWithString:self.imageUrl]];
}

+ (CGSize)getImageSize:(UIImage *)image
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    
    CGFloat imageWidth = image.size.width;
    CGFloat imageHeight = image.size.height;
    
    if (imageWidth < width && imageHeight < height) {
        return image.size;
    }else if (imageWidth > width && imageHeight > height) {
        CGFloat scaleWidth = imageWidth / width;
        CGFloat scaleHeight = imageHeight / height;
        CGFloat scale = MAX(scaleWidth, scaleHeight);
        return CGSizeMake(imageWidth / scale, imageHeight / scale);
    }else if (imageWidth > width && imageHeight < height){
        
        CGFloat scale = imageWidth / width;
        
        return CGSizeMake(imageWidth / scale, imageHeight / scale);
    }else if (imageWidth < width && imageHeight > height){
        CGFloat scale = imageHeight / height;
        return CGSizeMake(imageWidth / scale, imageHeight / scale);
    }else {
        return image.size;
    }
}
@end
